package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "200119",name="复印病历预约：DoAppointMedPrint()")
public class DoAppointMedPrintHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");

        // 住院号
        String inpNo = requestMessage.getArgsPropertyStringValue("inpNo");
        Assert.notNull(inpNo, "住院号（inpNo）： 不可为空！");
        // 住院次数
        String visitId = requestMessage.getArgsPropertyStringValue("visitId");
        Assert.notNull(visitId, "住院次数（visitId）： 不可为空！");
        // 患者姓名
        String patientName = requestMessage.getArgsPropertyStringValue("patientName");
        // 性别
        String sex = requestMessage.getArgsPropertyStringValue("sex");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        // 患者身份证正面照片数据流
        String idCardFrontImage = requestMessage.getArgsPropertyStringValue("idCardFrontImage");
        // 患者身份证背面照片数据流
        String idCardBehindImage = requestMessage.getArgsPropertyStringValue("idCardBehindImage");
        // 代办人姓名
        String agentName = requestMessage.getArgsPropertyStringValue("agentName");
        // 代办人与患者关系
        String agentRelationship = requestMessage.getArgsPropertyStringValue("agentRelationship");
        // 代办人身份证号
        String agentIdNo = requestMessage.getArgsPropertyStringValue("agentIdNo");
        // 代办人身份证正面照片数据流
        String agentIdCardFrontImage = requestMessage.getArgsPropertyStringValue("agentIdCardFrontImage");
        // 代办人身份证背面照片数据流
        String agentIdCardBehindImage = requestMessage.getArgsPropertyStringValue("agentIdCardBehindImage");
        // 代办人电话
        String agentPhoneNumber = requestMessage.getArgsPropertyStringValue("agentPhoneNumber");
        // 病历类型
        String medClass = requestMessage.getArgsPropertyStringValue("medClass");
        // 病历套餐编码(复印用途)
        String medPlanCode = requestMessage.getArgsPropertyStringValue("medPlanCode");
        // 复印用途描述
        String printPurposeDesc = requestMessage.getArgsPropertyStringValue("printPurposeDesc");
        // 复印份数
        String printNum = requestMessage.getArgsPropertyStringValue("printNum");
        Assert.notNull(printNum, "复印份数（printNum）： 不可为空！");
        // 备注
        String memo = requestMessage.getArgsPropertyStringValue("memo");
        // 领取方式
        String postWay = requestMessage.getArgsPropertyStringValue("postWay");
        Assert.notNull(postWay, "领取方式（postWay）： 不可为空！");
        // 支付方式
        String payWay = requestMessage.getArgsPropertyStringValue("payWay");
        // 收件人姓名
        String recipientName = requestMessage.getArgsPropertyStringValue("recipientName");
        // 收件人与患者关系
        String relationship = requestMessage.getArgsPropertyStringValue("relationship");
        // 收件地址
        String postAddr = requestMessage.getArgsPropertyStringValue("postAddr");
        // 收件人电话
        String recipientPhoneNumber = requestMessage.getArgsPropertyStringValue("recipientPhoneNumber");

        // 微信公众号注册手机号：微信消息推送用
        String wxUserMobile = requestMessage.getArgsPropertyStringValue("wxUserMobile");

        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参
        Map<String, Object> res = inHosAgent.doAppointMedPrint(channelCode, hospitalCode, inpNo, visitId, patientName, sex, idNo, idCardFrontImage, idCardBehindImage, agentName, agentRelationship, agentIdNo, agentIdCardFrontImage, agentIdCardBehindImage, agentPhoneNumber, medClass, medPlanCode, printPurposeDesc, printNum, memo, postWay, payWay, recipientName, relationship, postAddr, recipientPhoneNumber, wxUserMobile);

        // 设置应答信息
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
